package org.tsinghua.answer.domain.entity;

public class PaginationInfo {
	
	public static final int DEFAULT_DISPLAY=5;

	private int currentPage;
	private int startPage;
	private int endPage;
	private int totalPages;
	private boolean hasPrevious;
	private boolean hasNext;
	
	/**
	 * 
	 * @param totalPages
	 * @param currentPage 从0开始计算的page number
	 */
	public PaginationInfo(int totalPages, int currentPage) {
		this(totalPages, currentPage, DEFAULT_DISPLAY);
	}
	
	/**
	 * 
	 * @param totalPages
	 * @param currentPage 从0开始计算的page number
	 * @param displayCount
	 */
	public PaginationInfo(int totalPages, int currentPage, int displayCount) {
		currentPage++;
		setTotalPages(totalPages);
		setCurrentPage(currentPage);
		startPage = currentPage - currentPage % displayCount;
		if(startPage == 0) {
			startPage = 1;
		}
		endPage = currentPage + displayCount - currentPage % displayCount;
		if(endPage > totalPages) {
			endPage = totalPages;
		}
		hasPrevious = startPage != 1;
		hasNext = endPage != totalPages;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getStartPage() {
		return startPage;
	}
	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}
	public int getEndPage() {
		return endPage;
	}
	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	public boolean isHasPrevious() {
		return hasPrevious;
	}
	public void setHasPrevious(boolean hasPrevious) {
		this.hasPrevious = hasPrevious;
	}
	public boolean isHasNext() {
		return hasNext;
	}
	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}
}
